<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Clone index API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'indices-clone-index.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/indices-clone-index.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/indices-clone-index.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/indices-clone-index.html" rel="nofollow" target="_blank">../en/indices-clone-index.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="indices.html">Index APIs</a></span>
»
<span class="breadcrumb-node">Clone index API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="indices-clearcache.html">« Clear cache API</a>
</span>
<span class="next">
<a href="indices-close.html">Close index API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="indices-clone-index"></a>Clone index API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/clone-index.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Clones an existing index.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /twitter/_clone/cloned-twitter-index</pre>
</div>
<div class="console_widget" data-snippet="snippets/1614.console"></div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="clone-index-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/clone-index.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">POST /&lt;index&gt;/_clone/&lt;target-index&gt;</code></p>
<p><code class="literal">PUT /&lt;index&gt;/_clone/&lt;target-index&gt;</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="clone-index-api-prereqs"></a>Prerequisites<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/clone-index.asciidoc">edit</a>
</h3>
</div></div></div>
<p>To clone an index,
the index must be marked as read-only
and have a <a class="xref" href="cluster-health.html" title="Cluster health API">cluster health</a> status of <code class="literal">green</code>.</p>
<p>For example,
the following request prevents write operations on <code class="literal">my_source_index</code>
so it can be cloned.
Metadata changes like deleting the index are still allowed.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT /my_source_index/_settings
{
  "settings": {
    "index.blocks.write": true
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1615.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="clone-index-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/clone-index.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Use the clone index API
to clone an existing index into a new index,
where each original primary shard is cloned
into a new primary shard in the new index.</p>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="cloning-works"></a>How cloning works<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/clone-index.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Cloning works as follows:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
First, it creates a new target index with the same definition as the source
index.
</li>
<li class="listitem">
Then it hard-links segments from the source index into the target index. (If
the file system doesn’t support hard-linking, then all segments are copied
into the new index, which is a much more time consuming process.)
</li>
<li class="listitem">
Finally, it recovers the target index as though it were a closed index which
had just been re-opened.
</li>
</ul>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="clone-index"></a>Clone an index<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/clone-index.asciidoc">edit</a>
</h4>
</div></div></div>
<p>To clone <code class="literal">my_source_index</code> into a new index called <code class="literal">my_target_index</code>, issue
the following request:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /my_source_index/_clone/my_target_index</pre>
</div>
<div class="console_widget" data-snippet="snippets/1616.console"></div>
<p>The above request returns immediately once the target index has been added to
the cluster state — it doesn’t wait for the clone operation to start.</p>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>Indices can only be cloned if they meet the following requirements:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
The target index must not exist.
</li>
<li class="listitem">
The source index must have the same number of primary shards as the target index.
</li>
<li class="listitem">
The node handling the clone process must have sufficient free disk space to
accommodate a second copy of the existing index.
</li>
</ul>
</div>
</div>
</div>
<p>The <code class="literal">_clone</code> API is similar to the <a class="xref" href="indices-create-index.html" title="Create index API"><code class="literal">create index</code> API</a>
and accepts <code class="literal">settings</code> and <code class="literal">aliases</code> parameters for the target index:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /my_source_index/_clone/my_target_index
{
  "settings": {
    "index.number_of_shards": 5 <a id="CO567-1"></a><i class="conum" data-value="1"></i>
  },
  "aliases": {
    "my_search_indices": {}
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1617.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO567-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The number of shards in the target index. This must be equal to the
number of shards in the source index.</p>
</td>
</tr>
</table>
</div>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Mappings may not be specified in the <code class="literal">_clone</code> request. The mappings of
the source index will be used for the target index.</p>
</div>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="monitor-cloning"></a>Monitor the cloning process<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/clone-index.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The cloning process can be monitored with the <a class="xref" href="cat-recovery.html" title="cat recovery API"><code class="literal">_cat recovery</code>
API</a>, or the <a class="xref" href="cluster-health.html" title="Cluster health API"><code class="literal">cluster health</code> API</a> can be used to wait
until all primary shards have been allocated by setting the  <code class="literal">wait_for_status</code>
parameter to <code class="literal">yellow</code>.</p>
<p>The <code class="literal">_clone</code> API returns as soon as the target index has been added to the
cluster state, before any shards have been allocated. At this point, all
shards are in the state <code class="literal">unassigned</code>. If, for any reason, the target index
can’t be allocated, its primary shard will remain <code class="literal">unassigned</code> until it
can be allocated on that node.</p>
<p>Once the primary shard is allocated, it moves to state <code class="literal">initializing</code>, and the
clone process begins. When the clone operation completes, the shard will
become <code class="literal">active</code>. At that  point, Elasticsearch will try to allocate any
replicas and may decide to relocate the primary shard to another node.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="clone-wait-active-shards"></a>Wait for active shards<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/clone-index.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Because the clone operation creates a new index to clone the shards to,
the <a class="xref" href="indices-create-index.html#create-index-wait-for-active-shards" title="Wait For active shards">wait for active shards</a> setting
on index creation applies to the clone index action as well.</p>
</div>

</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="clone-index-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/clone-index.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;index&gt;</code>
</span>
</dt>
<dd>
(Required, string)
Name of the source index to clone.
</dd>
<dt>
<span class="term">
<code class="literal">&lt;target-index&gt;</code>
</span>
</dt>
<dd>
<p>(Required, string)
Name of the target index to create.</p>
<p>Index names must meet the following criteria:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Lowercase only
</li>
<li class="listitem">
Cannot include <code class="literal">\</code>, <code class="literal">/</code>, <code class="literal">*</code>, <code class="literal">?</code>, <code class="literal">"</code>, <code class="literal">&lt;</code>, <code class="literal">&gt;</code>, <code class="literal">|</code>, ` ` (space character), <code class="literal">,</code>, <code class="literal">#</code>
</li>
<li class="listitem">
Indices prior to 7.0 could contain a colon (<code class="literal">:</code>), but that’s been deprecated and won’t be supported in 7.0+
</li>
<li class="listitem">
Cannot start with <code class="literal">-</code>, <code class="literal">_</code>, <code class="literal">+</code>
</li>
<li class="listitem">
Cannot be <code class="literal">.</code> or <code class="literal">..</code>
</li>
<li class="listitem">
Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster)
</li>
<li class="listitem">
Names starting with <code class="literal">.</code> are deprecated, except for <a class="xref" href="index-modules.html#index-hidden">hidden indices</a> and internal indices managed by plugins
</li>
</ul>
</div>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="clone-index-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/clone-index.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">wait_for_active_shards</code>
</span>
</dt>
<dd>
<p>(Optional, string) The number of shard copies that must be active before
proceeding with the operation. Set to <code class="literal">all</code> or any positive integer up
to the total number of shards in the index (<code class="literal">number_of_replicas+1</code>).
Default: 1, the primary shard.</p>
<p>See <a class="xref" href="docs-index_.html#index-wait-for-active-shards" title="Active shards">Active shards</a>.</p>
</dd>
<dt>
<span class="term">
<code class="literal">master_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a response. If no response is received before the timeout expires, the request
fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="clone-index-api-request-body"></a>Request body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/indices/clone-index.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">aliases</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="indices-aliases.html" title="Update index alias API">alias object</a>)
Index aliases which include the target index.
See <a class="xref" href="indices-aliases.html" title="Update index alias API">Update index alias</a>.
</dd>
<dt>
<span class="term">
<code class="literal">settings</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="index-modules.html#index-modules-settings" title="Index Settings">index setting object</a>)
Configuration options for the target index.
See <a class="xref" href="index-modules.html#index-modules-settings" title="Index Settings">Index Settings</a>.
</dd>
</dl>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="indices-clearcache.html">« Clear cache API</a>
</span>
<span class="next">
<a href="indices-close.html">Close index API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>